#include "error.h"
#include "KOperationManager.h"

using namespace KSudoku;

#ifdef _DEBUG
void KOperationManager::AssertValid(const KOperationManager* pkObj) const
{
	assert(pkObj);
}
#endif // #ifdef _DEBUG

KOperationManager::KOperationManager(void)
{
}

KOperationManager::~KOperationManager(void)
{
}

bool KOperationManager::PushUndoOperation(int nY, int nX, int nValue)
{
	ASSERT_VALID(this);
	KOperation kOperation(nY, nX, nValue);
	m_kUndoStack.Push(kOperation);
	return true;
}

bool KOperationManager::PushRedoOperation(int nY, int nX, int nValue)
{
	ASSERT_VALID(this);
	KOperation kOperation(nY, nX, nValue);
	m_kRedoStack.Push(kOperation);
	return true;
}

bool KOperationManager::Undo(int& nY, int& nX, int& nValue)
{
	ASSERT_VALID(this);
	if (!m_kUndoStack.GetSize())
	{
		nY = 0;
		nX = 0;
		nValue = -1;
		return false;
	}
	KOperation kOperation(m_kUndoStack.GetTop());
	m_kUndoStack.Pop();
	nY = kOperation.GetY();
	nX = kOperation.GetX();
	nValue = kOperation.GetValue();

	return true;
}

bool KOperationManager::Redo(int& nY, int& nX, int& nValue)
{
	ASSERT_VALID(this);
	if (!m_kRedoStack.GetSize())
	{
		nY = 0;
		nX = 0;
		nValue = -1;
		return false;
	}
	KOperation kOperation(m_kRedoStack.GetTop());
	m_kRedoStack.Pop();
	nY = kOperation.GetY();
	nX = kOperation.GetX();
	nValue = kOperation.GetValue();

	return true;
}